package com.finger.gulimall.member.service.impl;

import com.finger.gulimall.member.vo.AddrFareVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.finger.common.utils.PageUtils;
import com.finger.common.utils.Query;

import com.finger.gulimall.member.dao.MemberReceiveAddressDao;
import com.finger.gulimall.member.entity.MemberReceiveAddressEntity;
import com.finger.gulimall.member.service.MemberReceiveAddressService;


@Service("memberReceiveAddressService")
public class MemberReceiveAddressServiceImpl extends ServiceImpl<MemberReceiveAddressDao, MemberReceiveAddressEntity> implements MemberReceiveAddressService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberReceiveAddressEntity> page = this.page(
                new Query<MemberReceiveAddressEntity>().getPage(params),
                new QueryWrapper<MemberReceiveAddressEntity>()
        );

        return new PageUtils(page);
    }
    /**
     * 计算运费
     * @param addrId
     * @return
     */
    @Override
    public AddrFareVo addrFare(Long addrId) {

        AddrFareVo addrFareVo = new AddrFareVo();
        MemberReceiveAddressEntity one = this.baseMapper.selectById(addrId);

        String phone = one.getPhone();
        // 模拟计算运费过程
        String price = phone.substring(phone.length() - 1);
        BigDecimal addrPrice = new BigDecimal(price);
        addrFareVo.setFare(addrPrice);
        addrFareVo.setMemberAddrVo(one);
        return addrFareVo;
    }
}